﻿using System;

class CalculateCatalanNumber

            // In the combinatorial mathematics, the Catalan numbers are calculated by the following formula: 
            // Write a program to calculate the Nth Catalan number by given N.

{
    static void Main()
    {
        Console.Write("Enter a value for 'N': ");
        int number = int.Parse(Console.ReadLine());
        double aFact = 1;
        double bFact = 1;
        double cFact = 1;
        for (int i = number * 2; i > 0; i--)
        {
            aFact *= i;
        }
        for (int j = number + 1; j > 0; j--)
        {
            bFact *= j;
        }
        for (int k = number; k > 0; k--)
        {
            cFact *= k;
        }
        Console.WriteLine();
        double catalanNumber = aFact / (bFact * cFact);
        Console.WriteLine("The catalan number is {0}", catalanNumber);
    }
}
